import { Loading } from 'element-ui'
import request from '@/utils/request'
export default {
  // 重启
  restart:function () {
    var _this=this

    console.log(request);

    request.getAjax({
      url:'?opt=device-reboot&unix-time='+new Date().getTime(),
      params:{}
    }).then(function (res) {
      console.log('重启回调参数',res);
      var loading = this.$loading({
        target:'.app-container',
        lock: true,
        text: '正在重启设备请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      }),
        restartStatus=false
      var restartInterval=setInterval(function () {
        if(restartStatus){
          console.log('重启成功');
          clearInterval(restartInterval)
        }else{
          _this.getversion(restartStatus)
        }

      },2000)
      // setTimeout(() => {
      //   loading.close();
      // }, 2000);
    }).catch(function (err) {
      console.log(err);
    }).finally(function (fn) {
      console.log(fn);
    })
  },
  // 获取版本信息
  getversion:function(restartStatus){
    var _this=this
    request.postAjax({
      method:'getversion',
      params:{}
    }).then(function (res) {
      console.log(res);
      if(res.result==0){
        setTimeout(function () {
          restartStatus=true
        },2000)
      }else{
        _this.tips(res.errorInfo.detail,'error')
      }
    }).catch(function (err) {
      console.log(err);
    }).finally(function (fn) {
      console.log(fn);
    })
  }
}
